import { FormSchema } from '/@/components/Table';
import { isRoleExist, listMenuScheme } from '/@/api/sys/role';
import { DescItem } from '/@/components/Description/index';
import { render } from '/@/utils/common/renderUtils';

export enum RoleEnum {
  OWNER = 'owner',
  ADMIN = 'admin',
  MEMBER = 'member',
}

export const columns = [
  {
    title: '角色名称',
    dataIndex: 'roleName',
    width: 100,
  },
  {
    title: '角色编码',
    dataIndex: 'roleCode',
    width: 100,
  },
  {
    title: '默认角色',
    dataIndex: 'isDefault',
    customRender: ({ text }) => {
      return render.renderTag(text ? '是' : '否', text ? 'green' : 'blue')
    },
    width: 60,
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    width: 140,
  },
  {
    title: '创建者',
    dataIndex: 'createdBy',
    width: 100,
  },
];
/**
 * 角色用户Columns
 */
export const userColumns = [
  {
    title: '用户账号',
    dataIndex: 'userName',
    width: 80,
  },
  {
    title: '用户姓名',
    dataIndex: 'realName',
    width: 80,
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = 'green'
      if (text === '2') {
        color = 'red'
      }
      return render.renderTag(render.renderDict(text, 'user_status'), color)
    },
    width: 50,
  }
];
export const searchFormSchema: FormSchema[] = [
  {
    field: 'roleName',
    label: '角色名称',
    component: 'Input',
    colProps: { span: 6},
  }
];


/**
 * 角色用户搜索form
 */
export const searchUserFormSchema: FormSchema[] = [
  {
    field: 'userName',
    label: '用户账号',
    component: 'Input',
    colProps: { span: 12 },
  },

];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show:false
  },
  {
    field: 'roleName',
    label: '角色名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'roleCode',
    label: '角色编码',
    required: true,
    component: 'Input',
  },
  {
    field: 'isDefault',
    label: '默认角色',
    component: 'RadioGroup',
    defaultValue: false,
    componentProps: {
      options: [
        { label: '是', value: true },
        { label: '否', value: false },
      ],
    }
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
      rows: 5,
    },
  }
];


export const formRolePermissionSchema: FormSchema[] = [
  {
    label: '场景',
    field: 'sceneCode',
    component: 'ApiSelect'
  }
];

export const formDetailSchema : DescItem[] = [
  {
    field: 'roleName',
    label: '角色名称',
  },
  {
    field: 'roleCode',
    label: '角色编码'
  },
  {
    label: '备注',
    labelMinWidth: 60,
    field: 'remark',
  }
];


